/******************************************************************************
Purpose: 		To prep and merge DHS individual country files and run analyses
                specified in the paper
Paper Title:	Adolescent Girls’ Safety In and Out of School: 
				Evidence on Physical and Sexual Violence
				from across Sub-Saharan Africa		
Authors:		Evans D.K., Hares S., Holland P. A., and Mendez Acosta A.
Journal:		Journal of Development Studies (forthcoming)
Input:			Individual Recode files in one folder ("IR") and Household Recode files
				in another folder ("HR") for the 20 countries covered in the analysis.
Output:			Merged DHS .dta file
				Tables of statistics (log-file and Excel files)
*******************************************************************************/

/**************************************
00. Housekeeping
***************************************/

* clear memory
	version 16.1
	clear
	clear 	matrix
	clear 	mata
	clear 	results
	set		more off
	set 	maxvar 30000

* set path files

	global parentfolder 	"INSERT FOLDER LOCATION HERE AND FOLDER NAME HERE"
	
	* FOR EXAMPLE:
	* global parentfolder 	"/Users/Downloads/Adolescent Girls’ Safety In and Out of School_Replication Files"

* globals and locals
	global 	outputfile	"DHS_merged.dta"
	global	logfile		"DHS_logfile"	

* log file
	capture log close _all
	log using "$parentfolder/$logfile", replace

/**************************************************
Program: myprepmerge
Purpose: Prep the IR and HR files and merge	
**************************************************/

	capture program drop myprepmerge
		program myprepmerge
		
			rename 	hv000 	countryphase
			rename 	hv001 	clusternumber
			rename 	hv002 	hhnumber
			
			* respondent's sex
			preserve
			
				forvalues i = 1/9 {
					rename 	hv104_0`i' hv104_`i'
				}
			
				keep countryphase clusternumber hhnumber hv104_*
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv104_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hv104_ sex				
			
				tempfile sexdata
				save `sexdata', replace
			
			restore
			
			* respondent's years attended school
			preserve
			
				forvalues i = 1/9 {
					rename 	hv108_0`i' hv108_`i'
				}
			
				keep countryphase clusternumber hhnumber hv108_*
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv108_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hv108_ educyears			
			
				tempfile highestyeardata
				save `highestyeardata', replace
			
			restore

			* educ attainment 
			preserve
				forvalues i = 1/9 {
					rename 	hv109_0`i' hv109_`i'
				}
				
				keep countryphase clusternumber hhnumber hv109_*
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv109_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hv109_ educattainment
				
				tempfile attainmentdata
				save `attainmentdata', replace
			
			restore			

			
			* highest schooling 
			preserve
				forvalues i = 1/9 {
					rename 	hv106_0`i' hv106_`i'
				}
				
				keep countryphase clusternumber hhnumber hv106_*
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv106_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hv106_ highestschool
				
				tempfile highestschooldata
				save `highestschooldata', replace
			
			restore

			
			* mom's highest schooling
			preserve
				forvalues i = 1/9 {
					rename 	hv112_0`i' hv112_`i'
				}
				
				keep countryphase clusternumber hhnumber hv112_*
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv112_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hhmember hhmember_temp
				rename hv112_ hhmember
				replace hhmember = -1 if hhmember == . //tag if respondents' mom's data is missing
				
				merge	m:1 countryphase clusternumber hhnumber hhmember using `highestschooldata'
				
				keep if _merge == 3 | _merge == 1
				drop _merge
				
				rename highestschool mom_highestschool
				drop hhmember
				rename hhmember_temp hhmember
				
				tempfile momdata
				save `momdata', replace
			
			restore

			*dad's highest schooling
			preserve
				forvalues i = 1/9 {
					rename 	hv114_0`i' hv114_`i'
				}
				
				keep countryphase clusternumber hhnumber hv114_*
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv114_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hhmember hhmember_temp
				rename hv114_ hhmember
				replace hhmember = -1 if hhmember == . //tag if respondent's dad's data is missing
				
				merge	m:1 countryphase clusternumber hhnumber hhmember using `highestschooldata'
				
				keep if _merge == 3 | _merge == 1
				drop _merge
				
				rename highestschool dad_highestschool
				drop hhmember
				rename hhmember_temp hhmember
				
				tempfile daddata
				save `daddata', replace
			
			restore
			
			*currently in school
			
				forvalues i = 1/9 {
					rename 	hv121_0`i' hv121_`i'
				}
				
				keep countryphase clusternumber hhnumber hv121_*  hv270 hv025
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				
				reshape long hv121_, i(countryphase clusternumber hhnumber) j(hhmember)
				
				rename hv121_ attendedschool	

				rename hv270 wealthindex
				rename hv025 urban
				replace urban = 0 if urban == 2
				
			* merge all HR data tempfiles
				merge	1:1 countryphase clusternumber hhnumber hhmember using `sexdata'
				keep if _merge == 3
				drop _merge
				
				merge	1:1 countryphase clusternumber hhnumber hhmember using `highestyeardata'
				keep if _merge == 3
				drop _merge

				merge	1:1 countryphase clusternumber hhnumber hhmember using `attainmentdata'
				keep if _merge == 3
				drop _merge
				
				merge	1:1 countryphase clusternumber hhnumber hhmember using `momdata'
				keep if _merge == 3
				drop _merge

				merge	1:1 countryphase clusternumber hhnumber hhmember using `daddata'
				keep if _merge == 3
				drop _merge
	
				tempfile HRfile
				save `HRfile', replace
				
			* prep Individual records
				use "$parentfolder/temp_IR.dta", clear	

			* prep for merge by renaming variables
				rename 	v000 	countryphase
				rename 	v001 	clusternumber
				rename 	v002 	hhnumber
				rename 	v003	hhmember
				
				keep countryphase clusternumber hhnumber hhmember v005 v012 v502 v044 d*
			
			* merge with household record to get schooling status
				drop if countryphase == "" | clusternumber == . | hhnumber == .
				merge 	1:1 countryphase clusternumber hhnumber hhmember using `HRfile'
				keep 	if _merge == 3
				drop 	_merge

		end


/**************************************************
 01. Append DHS country files
**************************************************/
		
	* save blank file
		gen 	blankvar=.
		cd 		"$parentfolder"
		save 	"$outputfile", replace
		
	* display names of all files for cleaning and merging
		cd "$parentfolder/HR"
		local allfiles : dir . files "*.DTA"
		display `allfiles'
	
	* loop over all datafiles
	
		foreach data of local allfiles{
		
			di "`data'"
			
			qui{
				
				* load the individual record to tempfile
				local	IRdata = substr("`data'", 1, 2) + "ir" + substr("`data'", -8, 8)
				use 	"$parentfolder/IR/`IRdata'", clear
				save 	"$parentfolder/temp_IR.dta", replace
				
				* load the household record
				use 	"$parentfolder/HR/`data'", clear
				
				myprepmerge

				append using "$parentfolder/$outputfile", force	// Appending all files together
				
				save "$parentfolder/$outputfile", replace			
			}
			
		}
		
	* create country code
		gen 	countrycode = substr(countryphase, 1, 2)		
		
	*countries
		gen 	country = ""
				
		replace country = "Angola"		if countrycode == "AO"
		replace country = "Benin"		if countrycode == "BJ"
		replace country = "Botswana"		if countrycode == "BT"			
		replace country = "Burkina Faso" if countrycode == "BF"			
		replace country = "Burundi" 	 if countrycode == "BU"
		replace country = "Congo"		if countrycode == "CG"	
		replace country = "Congo Dem Rep"	if countrycode == "CD"	
		replace country = "Cote d'Ivoire" if countrycode == "CI"		
		replace country = "Cameroon" 	if countrycode == "CM"		
		replace country = "Central African Rep" 	if countrycode == "CF"
		replace country = "Ethiopia"	if countrycode == "ET"
		replace country = "Gabon"		if countrycode == "GA"
		replace country = "Gambia"		if countrycode == "GM"
		replace country = "Ghana"		if countrycode == "GH" // Ghana's most recent round (DHS VII2) did not contain d106, d107 and d108
		replace country = "Guinea"		if countrycode == "GN"
		replace country = "Kenya"		if countrycode == "KE"
		replace country = "Madagascar" 	if countrycode == "MD"
		replace country = "Mali" 		if countrycode == "ML"
		replace country = "Malawi" 		if countrycode == "MW"		
		replace country = "Mozambique"	if countrycode == "MZ"
		replace country = "Nigeria"		if countrycode == "NG" //Niger 2012, 2006, 1998
		replace country = "Niger" 		if countrycode == "NI"	
		replace country = "Rwanda" 		if countrycode == "RW"
		replace country = "Senegal" 	if countrycode == "SN"		
		replace country = "Tanzania"	if countrycode == "TZ"
		replace country = "Chad" 		if countrycode == "TD"		
		replace country = "Uganda"		if countrycode == "UG"
		replace country = "South Africa" if countrycode == "ZA"
		replace country = "Zambia" 		if countrycode == "ZM"
		replace country = "Zimbabwe" 	if countrycode == "ZW"
		
		drop countrycode
		encode country, gen (countrycode)
	
	save "$parentfolder/$outputfile", replace	

/**************************************************
 02. Clean, label and generate variables
**************************************************/
		
	* generate violence indicators

		keep if v044 == 1 //interviewee was selected for domestic violence module and interviewed

		rename v012 age
		
		gen never_married = .
		replace never_married = 1 if v502 == 0
		replace never_married = 0 if v502 == 1 | v502 == 2
		
		
		*** sexual violence ever ***
		// reference: https://dhsprogram.com/data/Guide-to-DHS-Statistics/Experience_of_Sexual_Violence.htm
		// also: https://dhsprogram.com/pubs/pdf/DHSQMP/DHS6_Module_Domestic_Violence_6Aug2014_DHSQMP.pdf

		gen eversexviolence_husband = 0
		replace eversexviolence_husband = 1 if inrange(d105h,1,4) | inrange(d105i,1,4) | inrange(d105k, 1, 4) | inrange(d130b,1, 4)
		
		gen eversexviolence_others = 0
		replace eversexviolence_others = 1 if d124 == 1 | d125 == 1 // forced to perform unwanted sex acts with others ever

		gen eversexviolence = 0
		replace eversexviolence = 1 if eversexviolence_husband == 1 | eversexviolence_others == 1

		
		
		*** sexual violence in last 12 months ***
		// reference: https://dhsprogram.com/data/Guide-to-DHS-Statistics/Experience_of_Sexual_Violence.htm
		// also: https://dhsprogram.com/pubs/pdf/DHSQMP/DHS6_Module_Domestic_Violence_6Aug2014_DHSQMP.pdf
		
		gen sexviolence_husband = 0
		replace sexviolence_husband = 1 if inlist(d105h,1,2) | inlist(d105i,1,2) | inlist(d105k, 1, 2) | inlist(d130b,1)
		
		gen sexviolence_others = 0
		replace sexviolence_others = 1 if d124 == 1 // forced to perform unwanted sex acts with others in last 12 months
		
		gen sexviolence = 0
		replace sexviolence = 1 if sexviolence_husband == 1 | sexviolence_others == 1

		
		
		* physical violence ever
		//source: https://dhsprogram.com/data/Guide-to-DHS-Statistics/Experience_of_Physical_Violence.htm
		
		gen everphyviolence = 0
		replace everphyviolence = 1 if inrange(d105a, 1, 4) | inrange(d105b, 1, 4) | inrange(d105c, 1,4) | inrange(d105d, 1, 4) | inrange(d105e, 1, 4) | inrange(d105f, 1, 4) | inrange(d105g, 1, 4) | inrange(d105j, 1, 4) | inrange(d130a, 1, 4) | d115y == 0 | d118y == 0
		
		
		gen phyv_teacher = d115v
		recode phyv_teacher (9 = .)
	

		* physical violence past 12 months
		//reference: https://dhsprogram.com/data/Guide-to-DHS-Statistics/Experience_of_Physical_Violence.htm
		
		gen phyviolence = 0
		replace phyviolence = 1 if inrange(d105a, 1, 2) | inrange(d105b, 1, 2) | inrange(d105c, 1,2) | inrange(d105d, 1, 2) | inrange(d105e, 1, 2) | inrange(d105f, 1, 2) | inrange(d105g, 1, 2) | inrange(d105j, 1, 2) | d130a == 1 | inrange(d117a,1,2)
		
		
		gen phyviolence_partner = 0
		replace phyviolence_partner = 1 if inrange(d105a, 1, 2) | inrange(d105b, 1, 2) | inrange(d105c, 1,2) | inrange(d105d, 1, 2) | inrange(d105e, 1, 2) | inrange(d105f, 1, 2) | inrange(d105g, 1, 2) | inrange(d105j, 1, 2) | d130a == 1
		
		gen phyviolence_nonpartner = 0
		replace phyviolence_nonpartner = 1 if inrange(d117a,1,2)
	
		
		* physical OR sexual violence in the past 12 months
		
		gen violence = 0
		replace violence = 1 if phyviolence == 1 | sexviolence == 1

		
		* physical OR sexual violence ever
		
		gen everviolence = 0
		replace everviolence = 1 if everphyviolence == 1 | eversexviolence == 1

		
		* perpetrators of sexual violence
		
		gen first_sexviolence = 8 //others
		replace first_sexviolence = 1 if inrange(d127,1,2) // current or former husband
		replace first_sexviolence = 2 if inrange(d127,3,3) // current or former boyfriends
		replace first_sexviolence = 3 if inrange(d127,4,7) // family		
		replace first_sexviolence = 4 if d127 == 8 // friends
		replace first_sexviolence = 5 if d127 == 10 // teacher	
		replace first_sexviolence = 6 if d127 == 11 // employer	or someone at work
		replace first_sexviolence = 7 if d127 == 14 // employer	or someone at work
		replace first_sexviolence = . if inlist(d127, 99, .) // missing
		
		
		label def first_sexviolence 1 "current or former husband" 2 "current or former boyfriends" 3 "family" 4 "friends" 5"teacher" 6 "employer or someone at work" 7 "stranger" 8 "others"
		label values first_sexviolence first_sexviolence
	
	* weights
		gen wgt = d005/1000000 // domestic violence weight
		
		gen ssf = 0 //survey sampling fraction; respondents in the women's survey / total population of women 15-49 yo in the country at the time of the survey. Population data is from World Bank's WDI.
		//Source: https://userforum.dhsprogram.com/index.php?t=msg&th=5030&goto=9556&#msg_9556
		//See Pooled weights.xls for the computation of ssf.
		replace ssf = 0.00226461 if country == "Angola"
		replace ssf = 0.00119145 if country == "Congo Dem Rep"
		replace ssf = 0.00065116 if country == "Ethiopia"
		replace ssf = 0.00083857 if country == "Ghana"
		replace ssf = 0.00264821 if country == "Kenya"
		replace ssf = 0.00242094 if country == "Mozambique"
		replace ssf = 0.00093119 if country == "Nigeria"
		replace ssf = 0.00055428 if country == "South Africa"
		replace ssf = 0.00110557 if country == "Tanzania"
		replace ssf = 0.00199696 if country == "Uganda"
		
		replace ssf = 0.00477372 if country == "Burkina Faso"
		replace ssf = 0.00592877 if country == "Chad"
		replace ssf = 0.00207073 if country == "Cote d'Ivoire"
		replace ssf = 0.00241281 if country == "Cameroon"
		replace ssf = 0.00248229 if country == "Mali"
		//replace ssf = 0.00290508 if country == "Malawi"
		replace ssf = 0.00617946  if country == "Malawi"
		replace ssf = 0.00486461 if country == "Rwanda"
		replace ssf = 0.00216139 if country == "Senegal"
		replace ssf = 0.00198865 if country == "Zambia"
		replace ssf = 0.00265922 if country == "Zimbabwe"

		gen pooled_wgt = wgt/ssf
		
	* controls
	
		gen missing_mom_edu = (mom_highestschool == .)
		gen missing_dad_edu = (dad_highestschool == .)
		
		recode mom_highestschool (. = 0) (8 = 0)
		recode dad_highestschool (. = 0) (8 = 0)
		
		recode attendedschool (9 = .)
		recode attendedschool (2 = 1)
		
	* hhID for clustering SEs
		
		tostring clusternumber hhnumber, gen(cluster_str hh_str)
		gen hhid = country + cluster_str + hh_str
		
	* other variables
	
		* total years of education
		tab educyears, m nol
		recode educyears (98/99 = .)
		
		* indicator for currently in secondary school
		gen current_secondary = .
		replace current_secondary = 0 if attendedschool == 0 & educattainment <= 3 // not in school AND highest educ attainment is incomplete secondary
		replace current_secondary = 1 if attendedschool == 1 & (educattainment == 3 | educattainment == 2)  // in school AND highest educ attainment is incomplete secondary or complete primary
		
			
/**************************************************
 03. Tables
**************************************************/
	
	
	/*********************************************************************
	   Table 1. Proportion of girls ages 15-19 years old who experienced
	   physical or sexual violence previously (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
	
		* row 1 (experience of physical or sexual violence, all girls, pooled)
		tab everviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab everviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if everviolence != . //obs
		
		* column 1, 3 and 5 (experience of physical or sexual violence, girls by school attendance)
		tab country [aweight = wgt], sum(everviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(everviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(everviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if everviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg everviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui 	outreg2 using "$parentfolder/Table 1_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence previously, clustered SE)		///
						dec(3)
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg everviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table 1_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
			qui 	reg everviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
						i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
			qui 	outreg2 using "$parentfolder/Table 1_adjusted difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence previously, clustered SE)	///
						dec(3)
				
			* individual countries		
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg everviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
						missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table 1_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
			
		restore
		
	/*********************************************************************
	   Table 2. Distribution of perpetrators of first sexual violence
	   among girls ages 15-19 years old who report having experienced 
	   sexual violence previously (DHS data)
	*********************************************************************/	
		
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* with DV weights, denominator are observations that experienced violence AND reported a perpetrator
	
		* clean data; recode missing answers
		tab first_sexviolence if eversexviolence == 1, m
		replace first_sexviolence = 9 if eversexviolence == 1 & first_sexviolence == .
		
		* column 1
		tab first_sexviolence if eversexviolence == 1 [iweight = pooled_wgt]
		
		* column 2 and 3
		bys attendedschool: tab first_sexviolence if eversexviolence == 1 [aweight = wgt]
		
		restore
		
	/*********************************************************************
	   Table A1. Proportion of girls ages 15-19 years old who experienced
	   physical violence previously (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of physical violence, all girls, pooled)
		tab everphyviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab everphyviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if everphyviolence != . //obs
		
		* column 1, 3 and 5 (experience of physical, girls by school attendance)
		tab country [aweight = wgt], sum(everphyviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(everphyviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(everphyviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if everphyviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg everphyviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A1_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical violence previously, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg everphyviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A1_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg everphyviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A1_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced physical violence previously, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg everphyviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A1_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
	
		restore
		
	/*********************************************************************
	   Table A2. Proportion of girls ages 15-19 years old who experienced
	   sexual violence previously (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of sexual violence, all girls, pooled)
		tab eversexviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab eversexviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if eversexviolence != . //obs
		
		* column 1, 3 and 5 (experience of sexual violence, girls by school attendance)
		tab country [aweight = wgt], sum(eversexviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(eversexviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(eversexviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if eversexviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg eversexviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A2_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced sexual violence previously, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg eversexviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A2_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg eversexviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A2_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced sexual violence previously, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg eversexviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A2_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		restore
	
	/*********************************************************************************
	   Table A3. Proportion of girls ages 15-19 years old who have never been married
	   or partnered and who have experienced physical violence previously (DHS data)
	**********************************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		keep if never_married == 1 // for the sub-analysis of the non-married girls
	
		* row 1 (experience of physical violence, all girls, pooled)
		tab everphyviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab everphyviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if everphyviolence != . //obs
		
		* column 1, 3 and 5 (experience of physical, girls by school attendance)
		tab country [aweight = wgt], sum(everphyviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(everphyviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(everphyviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if everphyviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg everphyviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A3_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical violence previously, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg everphyviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A3_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg everphyviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A3_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced physical violence previously, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg everphyviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A3_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}	

		restore
	
	
	
	/*********************************************************************************
	   Table A4. Proportion of girls ages 15-19 years old who have never been married
	   or partnered and who have experienced sexual violence previously (DHS data)
	**********************************************************************************/
	
		preserve
				
		keep if age < 20 // age = 15 to 19
		keep if never_married == 1 // for the sub-analysis of the non-married girls
	
		* row 1 (experience of sexual violence, all girls, pooled)
		tab eversexviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab eversexviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if eversexviolence != . //obs
		
		* column 1, 3 and 5 (experience of sexual, girls by school attendance)
		tab country [aweight = wgt], sum(eversexviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(eversexviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(eversexviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if eversexviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg eversexviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A4_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced sexual violence previously, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg eversexviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A4_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg eversexviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A4_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced sexual violence previously, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg eversexviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A4_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}	

		restore
	
	
	/*********************************************************************
	   Table A5. Proportion of girls ages 15-19 years old who experienced
	   physical or sexual violence in the last 12 months (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of physical or sexual violence, all girls, pooled)
		tab violence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab violence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if violence != . //obs
		
		* column 1, 3 and 5 (experience of physical or sexual violence, girls by school attendance)
		tab country [aweight = wgt], sum(violence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(violence)
		tab country [aweight = wgt] if attendedschool == 1, sum(violence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if violence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg violence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui 	outreg2 using "$parentfolder/Table A5_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg violence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A5_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
			qui 	reg violence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
						i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
			qui 	outreg2 using "$parentfolder/Table A5_adjusted difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence in the past 12 months, clustered SE)	///
						dec(3)
				
			* individual countries		
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg violence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
						missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A5_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		restore
	
	
	/*********************************************************************
	   Table A6. Proportion of girls ages 15-19 years old who experienced
	   physical violence in the last 12 months (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of physical violence, all girls, pooled)
		tab phyviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab phyviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if phyviolence != . //obs
		
		* column 1, 3 and 5 (experience of physical, girls by school attendance)
		tab country [aweight = wgt], sum(phyviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(phyviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(phyviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if phyviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg phyviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A6_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg phyviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A6_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg phyviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A6_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced physical violence in the past 12 months, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg phyviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A6_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
	
		restore
		
	/*********************************************************************
	   Table A7. Proportion of girls ages 15-19 years old who experienced
	   sexual violence in the last 12 months (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of sexual violence, all girls, pooled)
		tab sexviolence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab sexviolence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if sexviolence != . //obs
		
		* column 1, 3 and 5 (experience of sexual violence, girls by school attendance)
		tab country [aweight = wgt], sum(sexviolence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(sexviolence)
		tab country [aweight = wgt] if attendedschool == 1, sum(sexviolence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if sexviolence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg sexviolence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A7_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced sexual violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg sexviolence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A7_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg sexviolence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A7_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced sexual violence in the past 12 months, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg sexviolence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A7_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///	
							ctitle("`countryX'")		///
							dec(3)
			}

		restore
			
	/*******************************************************************************
	   Table A8. Regressing the probability of having experienced physical
	   or sexual violence previously against the total years of education attained
	   for girls ages 15-19 year old (DHS data) 
	*********************************************************************************/
		
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* column 1 and 2; experience of physical or sexual violence, simple difference
		
			* pooled
				qui 	reg everviolence educyears [pweight = pooled_wgt], cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced violence previously, simple difference)		///
							dec(3)
							
			* individual countries		
				levelsof country
				foreach countryX in `r(levels)' {
					qui 	reg everviolence educyears [pweight = wgt] if country == "`countryX'", cluster(hhid) 
					qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
								append ///
								label ///
								ctitle("`countryX', simple difference")		///
								dec(3)
				}
		
			
		* column 3; experience of physical or sexual violence, adjusted difference
			
			* pooled
				qui 	reg everviolence educyears i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu i.age [pweight = pooled_wgt], cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle(Experienced violence previously, adjusted difference)		///
							dec(3)
			* all countries		
				levelsof country
				foreach countryX in `r(levels)' {
					qui 	reg everviolence educyears i.wealthindex urban i.age i.mom_highestschool ///
								i.dad_highestschool missing_mom_edu missing_dad_edu i.age [pweight = wgt] ///
								if country == "`countryX'", cluster(hhid) 
					qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference")		///
							dec(3)
				}
		
	
	
		* column 4; experience of physical violence, simple difference
		
			* pooled
				qui 	reg everphyviolence educyears [pweight = pooled_wgt], cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle(Experienced physical violence previously, simple difference)		///
							dec(3)
							
			* individual countries		
				levelsof country
				foreach countryX in `r(levels)' {
					qui 	reg everphyviolence educyears [pweight = wgt] if country == "`countryX'", cluster(hhid) 
					qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
								append ///
								label ///
								ctitle("`countryX', simple difference")		///
								dec(3)
				}
		
			
		* column 5; experience of physical violence, adjusted difference
			
			* pooled
				qui 	reg everphyviolence educyears i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu i.age [pweight = pooled_wgt], cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle(Experienced physical violence previously, adjusted difference)		///
							dec(3)
			* all countries		
				levelsof country
				foreach countryX in `r(levels)' {
					qui 	reg everphyviolence educyears i.wealthindex urban i.age i.mom_highestschool ///
								i.dad_highestschool missing_mom_edu missing_dad_edu i.age [pweight = wgt] ///
								if country == "`countryX'", cluster(hhid) 
					qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference")		///
							dec(3)
				}	
	
	
		* column 6; experience of sexual violence, simple difference
		
			* pooled
				qui 	reg eversexviolence educyears [pweight = pooled_wgt], cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle(Experienced sexual violence previously, simple difference)		///
							dec(3)
							
			* individual countries		
				levelsof country
				foreach countryX in `r(levels)' {
					qui 	reg eversexviolence educyears [pweight = wgt] if country == "`countryX'", cluster(hhid) 
					qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
								append ///
								label ///
								ctitle("`countryX', simple difference")		///
								dec(3)
				}
		
			
		* column 7; experience of sexual violence, adjusted difference
			
			* pooled
				qui 	reg eversexviolence educyears i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu i.age [pweight = pooled_wgt], cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle(Experienced sexual violence previously, adjusted difference)		///
							dec(3)
			* all countries		
				levelsof country
				foreach countryX in `r(levels)' {
					qui 	reg eversexviolence educyears i.wealthindex urban i.age i.mom_highestschool ///
								i.dad_highestschool missing_mom_edu missing_dad_edu i.age [pweight = wgt] ///
								if country == "`countryX'", cluster(hhid) 
					qui 	outreg2 using "$parentfolder/Table A8.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX', adjusted difference")		///
							dec(3)
				}		
	
	
		restore
		
	/*********************************************************************
	   Table A9. Proportion of girls ages 20-24 years old who experienced
	   physical or sexual violence in the last 12 months (DHS data) 
	*********************************************************************/
		
		preserve
		
		keep if age >= 20 & age <= 24 // age = 20 to 24
		
		* row 1 (experience of physical or sexual violence, all girls, pooled)
		tab violence [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab violence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if violence != . //obs
		
		* column 1, 3 and 5 (experience of physical or sexual violence, girls by school attendance)
		tab country [aweight = wgt], sum(violence) 
		tab country [aweight = wgt] if attendedschool == 0, sum(violence)
		tab country [aweight = wgt] if attendedschool == 1, sum(violence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if violence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg violence attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui 	outreg2 using "$parentfolder/Table A9_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg violence attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A9_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
			qui 	reg violence attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
						i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
			qui 	outreg2 using "$parentfolder/Table A9_adjusted difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence in the past 12 months, clustered SE)	///
						dec(3)
				
			* individual countries		
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg violence attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
						missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A9_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
				
		
		restore
		
	
	/*********************************************************************
	   Table A10. Proportion of girls ages 20-24 years old who experienced
	   physical or sexual violence in the last 12 months
	   according to attendance in secondary schools(DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age >= 20 & age <= 24 // age = 20 to 24
		drop if current_secondary == .
		
		* row 1 (experience of physical or sexual violence, all girls, pooled)
		tab violence [iweight = pooled_wgt] //all-country pooled
		bysort current_secondary: tab violence [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if violence != . //obs
	
		* column 1, 3 and 5 (experience of physical or sexual violence, girls by secondary school attendance)
		tab country [aweight = wgt], sum(violence) 
		tab country [aweight = wgt] if current_secondary == 0, sum(violence)
		tab country [aweight = wgt] if current_secondary == 1, sum(violence)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort current_secondary: tab country if violence != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg violence current_secondary [pweight = pooled_wgt], cluster(hhid) 
			qui 	outreg2 using "$parentfolder/Table A10_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg violence current_secondary [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A10_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
			qui 	reg violence current_secondary i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
						i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
			qui 	outreg2 using "$parentfolder/Table A10_adjusted difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical or sexual violence in the past 12 months, clustered SE)	///
						dec(3)
				
			* individual countries		
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg violence current_secondary i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
						missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A10_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
				
		
		restore	
	
	
	/*********************************************************************
	   Table A20. Proportion of girls ages 15-19 years old who experienced
	   physical violence in the last 12 months (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of physical violence, all girls, pooled)
		tab phyviolence_partner [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab phyviolence_partner [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if phyviolence_partner != . //obs
		
		* column 1, 3 and 5 (experience of physical, girls by school attendance)
		tab country [aweight = wgt], sum(phyviolence_partner) 
		tab country [aweight = wgt] if attendedschool == 0, sum(phyviolence_partner)
		tab country [aweight = wgt] if attendedschool == 1, sum(phyviolence_partner)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if phyviolence_partner != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg phyviolence_partner attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A20_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg phyviolence_partner attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A20_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg phyviolence_partner attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A20_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced physical violence in the past 12 months, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg phyviolence_partner attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A20_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
	
		restore
		
	
	/*********************************************************************
	   Table A21. Proportion of girls ages 15-19 years old who experienced
	   physical violence in the last 12 months (DHS data) 
	*********************************************************************/
	
		preserve
		
		keep if age < 20 // age = 15 to 19
		
		* row 1 (experience of physical violence, all girls, pooled)
		tab phyviolence_nonpartner [iweight = pooled_wgt] //all-country pooled
		bysort attendedschool: tab phyviolence_nonpartner [iweight = pooled_wgt] //all-country pooled
	
		* column 2 (number of observations, all girls)
		tab country if phyviolence_nonpartner != . //obs
		
		* column 1, 3 and 5 (experience of physical, girls by school attendance)
		tab country [aweight = wgt], sum(phyviolence_nonpartner) 
		tab country [aweight = wgt] if attendedschool == 0, sum(phyviolence_nonpartner)
		tab country [aweight = wgt] if attendedschool == 1, sum(phyviolence_nonpartner)
		
		* column 4 and 6 (number of observations, girls by school attendance)
		bysort attendedschool: tab country if phyviolence_nonpartner != . //obs
	
		* column 7, simple difference
			* pooled
			qui 	reg phyviolence_nonpartner attendedschool [pweight = pooled_wgt], cluster(hhid) 
			qui		outreg2 using "$parentfolder/Table A21_simple difference.xls", /// // output file and formatting
						replace ///
						label ///
						ctitle(Experienced physical violence in the past 12 months, clustered SE)		///
						dec(3)
			* individual countries	
			levelsof country
			foreach countryX in `r(levels)' {
				qui		reg phyviolence_nonpartner attendedschool [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui		outreg2 using "$parentfolder/Table A21_simple difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
		
		* column 8, adjusted difference
			* pooled
				qui 	reg phyviolence_nonpartner attendedschool i.wealthindex urban i.countrycode i.age i.mom_highestschool ///
							i.dad_highestschool missing_mom_edu missing_dad_edu [pweight = pooled_wgt], cluster(hhid)
				qui 	outreg2 using "$parentfolder/Table A21_adjusted difference.xls", /// // output file and formatting
							replace ///
							label ///
							ctitle(Experienced physical violence in the past 12 months, clustered SE)	///
							dec(3)
			
			* individual countries
			levelsof country
			foreach countryX in `r(levels)' {
				qui 	reg phyviolence_nonpartner attendedschool i.wealthindex urban i.age i.mom_highestschool i.dad_highestschool ///
							missing_mom_edu missing_dad_edu [pweight = wgt] if country == "`countryX'", cluster(hhid) 
				qui 	outreg2 using "$parentfolder/Table A21_adjusted difference.xls", /// // output file and formatting
							append ///
							label ///
							ctitle("`countryX'")		///
							dec(3)
			}
	
		restore
		
	
	* close log file and convert to PDF
	
	translate "$parentfolder/$logfile.smcl" "$parentfolder/$logfile.pdf", replace
	
	*************************************** END OF CODE *****************************************
			
		
